//  app                  filename  var len
//./file_wr_float.a.out  ./wr.txt   2  128
//./file_wr_float        ./wr.txt   2  128



#include <stdio.h>
#include <stdlib.h>
#include <stdint.h> //uint8_t
#include <sys/mman.h> //mmap
#include <assert.h>  //assert
#include <fcntl.h>   //O_RDWR
#include <unistd.h>

#define VAREC_IP_REG_MAP_RANGE    0x2000 
//2
#define WMEM_BASE_ADDR      0x60000000L 
//2
#define RMEM_BASE_ADDR     0x60002000L
//4
#define WDMA_BASE_ADDR     0x60004010L
#define RDMA0_BASE_ADDR    0x60004000L
#define RDMA1_BASE_ADDR    0x60004008L

#define WREG_BASE_ADDR     0x60004018L
#define RREG_BASE_ADDR     0x60004020L


#define FILESIZE  1024 


int main(int argc, char* argv[]) {

        printf("filename is %0s  ,data_len is %0d  !!! \n" , argv[1] , atoi(argv[2]) ) ;
		printf("\n") ;

        FILE * fpr = fopen( argv[1]  , "rb");
        FILE * fpw  ;
	    unsigned char   rcdata ;
		unsigned int rcnt      ;
		unsigned int fcnt      ;
		char fwname [10];


		rcnt = 0 ;
		fcnt = 0 ;
		rcdata = 0 ;
		
			
		while (1)
		{
		   		fread (&rcdata,1,1,fpr);
		   		if(feof(fpr))
				{  
			  		 break ;
				}
				else {

					if (rcnt == 0 ){
					    sprintf(fwname,"split%0d",fcnt) ;
						fcnt = fcnt + 1 ;
						fpw = fopen( fwname  , "w");
						printf("filename   is %0s   \n",fwname);
					}


				    fwrite (&rcdata,1,1,fpw);
			 	  	//printf("read byte data  is %0d   \n",rcdata);
				    rcnt      = rcnt     + 1 ;
					if (rcnt==atoi(argv[2])) {
				    	rcnt      =  0 ;
   						fclose(fpw) ;						
					}
				}
		}

   		fclose(fpr) ;

		return 0;

}

